{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example - Executing a notebook from python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How to add a parameter tag\n",
    "\n",
    "If you wanted to add your own parameter tag, you would go to the menu: View ➡️ Cell Toolbar ➡️ Tags\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Input notebook\n",
    "\n",
    "Let's take a look at the input notebook (`simple_input.ipynb`). This notebook has cells containing\n",
    "tags for the parameters. \n",
    "\n",
    "[See input notebook](simple_input.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Execute using the Python\n",
    "\n",
    "We are going to use papermill's python interface to execute the notebook\n",
    "\n",
    "The command takes the form:\n",
    "\n",
    "`pm.execute_notebook(input, output, parameters={param_name: param_value}`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "tags": [
     "parameters"
    ]
   },
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "/home/mseal/Workspace/papermill/binder/cli-simple",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-11-9365d48b7dea>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mbinder_dir2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'..'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mabspath\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mException\u001b[0m: /home/mseal/Workspace/papermill/binder/cli-simple"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import papermill as pm\n",
    "\n",
    "binder_dir = '..'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = pm.execute_notebook(\n",
    "    os.path.join(binder_dir, 'cli-simple', 'simple_input.ipynb'),\n",
    "    os.path.join(binder_dir, 'cli-simple', 'simple_output.ipynb'),\n",
    "    parameters={'msg': 'Hello'}\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
